from mainapp.models import TUser, TNews, TNewsType


def page_(uid, newsid):
    user = TUser.objects.get(pk=uid)
    news = TNews.objects.filter(user=user)
    l = []
    data = {}
    for n in news:
        l.append(n.id)
    print(l, type(newsid), newsid)
    m = l.index(int(newsid))
    if m > 0:
        left = m - 1
        data['left'] = (TNews.objects.get(pk=l[left]).title, TNews.objects.get(pk=l[left]).id)
    else:
        data['left'] = ('没有了', 0)
    if m < len(l) - 1:
        right = m + 1
        data['right'] = (TNews.objects.get(pk=l[right]).title, TNews.objects.get(pk=l[right]).id)
    else:
        data['right'] = ('没有了', 0)
    btype = TNewsType.objects.get(pk=1)
    b_news = TNews.objects.filter(user=user, news_type=btype).order_by('-id')[:3]
    # print(b_news)
    l_ = []
    for n in b_news:
        v = (n.title, n.id)
        print(v)
        l_.append(v)
    data['b_news'] = l_
    data['v_news'] = []
    data['o_news'] = []
    return data


